package io.renren.modules.eightapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.eightapp.dao.EiRepairInfoDao;
import io.renren.modules.eightapp.dto.EiRepairDTO;
import io.renren.modules.eightapp.dto.EiRepairInfoDTO;
import io.renren.modules.eightapp.entity.EiComplainInfoEntity;
import io.renren.modules.eightapp.entity.EiRepairInfoEntity;
import io.renren.modules.eightapp.service.EiRepairInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author Mark 1132115960@gmail.com
 * @since 1.0.0 2022-12-27
 */
@Service
public class EiRepairInfoServiceImpl extends CrudServiceImpl<EiRepairInfoDao, EiRepairInfoEntity, EiRepairInfoDTO> implements EiRepairInfoService {

    @Autowired
    private EiRepairInfoDao eiRepairInfoDao;

    @Override
    public int updateStateById(Integer id) {
        EiRepairInfoEntity eiRepairInfoEntity = new EiRepairInfoEntity();
        eiRepairInfoEntity.setState(1);
        eiRepairInfoEntity.setId(id);
        int i = eiRepairInfoDao.updateById(eiRepairInfoEntity);
        return i;
    }

    @Override
    public List<EiRepairInfoDTO> getRepairListByOwnerId(int ownerId) {
        QueryWrapper<EiRepairInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select().eq(EiRepairInfoEntity::getOwnerId,ownerId);
        List<EiRepairInfoEntity> eiRepairInfoEntities = eiRepairInfoDao.selectList(queryWrapper);
        List<EiRepairInfoDTO> list = ConvertUtils.sourceToTarget(eiRepairInfoEntities, EiRepairInfoDTO.class);
        return list;
    }

    @Override
    public EiRepairInfoDTO getRepairById(int id) {
        EiRepairInfoEntity eiRepairInfoEntity = eiRepairInfoDao.selectById(id);
        EiRepairInfoDTO eiRepairInfoDTO = ConvertUtils.sourceToTarget(eiRepairInfoEntity, EiRepairInfoDTO.class);
        return eiRepairInfoDTO;
    }

    @Override
    public int deleteRepairById(int id) {
        int i = eiRepairInfoDao.deleteById(id);
        return i;
    }

    @Override
    public int deleteRepairList(List<Integer> ids) {
        int i = eiRepairInfoDao.deleteBatchIds(ids);
        return i;
    }

    @Override
    public QueryWrapper<EiRepairInfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<EiRepairInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public Integer getStateListById(List<Integer> ids) {
        List<EiRepairInfoEntity> list = eiRepairInfoDao.selectBatchIds(ids);
        for(int i=0;i<list.size();i++) {
            if(list.get(i).getState() == 1) {
                return 1;
            }
        }
        return 0;
    }

    @Override
    public List<EiRepairDTO> getRepairList() {
        List<EiRepairDTO> repairList = eiRepairInfoDao.getRepairList();
        return repairList;
    }
}